﻿/**
*DialogFrameView class
*auth:lww
*version:1.0
*date:2014-10-11
*/
function DialogFrameView(context) {
    this.id = "";
    this.name = "DialogFrameView";
    this.version = "1.0.0";
    this.mContext = context;
    this.mLayoutParams = null;
    this.mViewObject = null;
    this.contentViewObject = null;
    this.isRoundCorner = true;
    this.isShowTitle = true;
    this.isCanCloseByUser = true;
    /**
    *info
    */
    this.mTitleBar = null;
    this.mFrameView = null;
    this.mIco = DefaultIcoInfo;
    this.titleText = "";
    this.frameUrl = "";
    this.mWdith = 640;
    this.mHeight = 480;
}

DialogFrameView.prototype.setWidth = function (w) {
    this.mWdith = w;
};

DialogFrameView.prototype.getWidth = function () {
    return this.mWdith;
};

DialogFrameView.prototype.setHeight = function (h) {
    this.mHeight = h;
};

DialogFrameView.prototype.getHeight = function () {
    return this.mHeight;
};

DialogFrameView.prototype.setIsCanCloseByUser = function (b) {
    this.isCanCloseByUser = b;
};

DialogFrameView.prototype.setIco = function (ico) {
    this.mIco = ico;
};

DialogFrameView.prototype.invalidate = function () {
    if (this.mViewObject == null) {
        this.mViewObject = new LinearLayout(this.mContext);
    }
    if (this.mLayoutParams == null) {
        this.mLayoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
    }
    this.mViewObject.setLayoutParams(this.mLayoutParams);
    return this.mViewObject.view();
};

DialogFrameView.prototype.view = function () {
    return this.invalidate();
};

DialogFrameView.prototype.getDragView = function () {
    if (this.mTitleBar != null) {
        return this.mTitleBar.view();
    }
    return null;
};

DialogFrameView.prototype.getId = function () {
    if (this.id == null || this.id == "") {
        this.id = id();
    }
    return this.id;
};

DialogFrameView.prototype.setId = function (ids) {
    this.id = ids;
};

DialogFrameView.prototype.createFrame = function () {
    if (this.mFrameView != null) {
        if (this.mTitleBar != null){
            this.mTitleBar.setInnerHTML(this.titleText);
        }            
        this.mFrameView.setSrc(this.frameUrl);
        return;
    }
    if (this.isShowTitle) {
        this.mTitleBar = new LinearLayout(this.mContext);
        this.mTitleBar.setLayoutParams(new LayoutParams(MATCH_PARENT, 26));
        this.mTitleBar.setBackground(new Drawable(DefaultBgColor, null));
        this.mTitleBar.addChildView(formatHtmlIco(this.mIco, "18px", "18px", "4px 0 0 4px", this.titleText));
        this.mTitleBar.addChildView(formatHtmlString(this.titleText, "#fff", "12px", "bold", "5px 0 0 2px"));
        if (this.isCanCloseByUser) {
            var marginStr = "4px 3px 0 0"; 
            var floatStr = "right";                        
            if (this.mWdith > 0) {//please check browse version and do the flown set 
                //var marginleft = getStrLenWithGB(this.titleText) * 11.5 + 12; //font.size:12px
                //var rightMargin = this.mWdith - marginleft;               
                //marginStr = "4px 0 0 " + rightMargin.toString() + "px"; 
                //floatStr = null;
            }    
            var closeBtn = formatHtmlIco(DefaultIcoClose, "18px", "18px", marginStr, "关闭", floatStr);
            closeBtn.style.cursor = "pointer";
            var o = this; closeBtn.onclick = function () {
                o.onClose(o, ButtonEventClose);
            };
            this.mTitleBar.addChildView(closeBtn);               
        }
    }
    this.mFrameView = new FragmentView(this.mContext);
    this.mFrameView.setLayoutParams(new LayoutParams(MATCH_PARENT, this.getHeight()));
    this.mFrameView.setBackground(new Drawable("#ffffff", null));
    this.mFrameView.setSrc(this.frameUrl);
    if (this.mViewObject == null) {
        this.invalidate();
    }
    if (this.isRoundCorner) {
        this.mViewObject.setClassName("color1");
        for (var i = 1; i < 5; i++) {
            var bt = $c("b", id()); bt.className = "b" + i.toString();
            this.mViewObject.addChildView(bt);
        }
        this.contentViewObject = new LinearLayout(this.mContext);
        this.contentViewObject.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
        this.contentViewObject.setClassName("content");
        this.contentViewObject.setBackground(new Drawable(DefaultContentViewBgColor, null));
        this.mViewObject.addChildView(this.contentViewObject.view());
        for (i = 5; i < 9; i++) {
            var bb = $c("b", id()); bb.className = "b" + i.toString();
            this.mViewObject.addChildView(bb);
        }
        if (this.mTitleBar != null){
            this.contentViewObject.addChildView(this.mTitleBar.view());
        }                
        this.contentViewObject.addChildView(this.mFrameView.view());
    }
    else {
        if (this.mTitleBar != null){
            this.mViewObject.addChildView(this.mTitleBar.view());
        }               
        this.mViewObject.addChildView(this.mFrameView.view());
    }    
};

DialogFrameView.prototype.setFrameInfo = function (title, url, isShowTitle) {
    this.titleText = title;
    this.frameUrl = url;
    if (typeof (isShowTitle) != 'undefined' && isShowTitle != null) {
        this.isShowTitle = isShowTitle;
    }
    //create Frame
    this.createFrame();
};

DialogFrameView.prototype.onClose = function (refObj, type) {
    //set to your callback:close interface   
};

DialogFrameView.prototype.getDocument = function () {
    if (this.mFrameView != null) {
        return this.mFrameView.getDocument();
    }
    return null;
};

markscript("DialogFrameView");
//end DialogFrameView.js